<?php
class Zendvn_Models_Home extends Zend_Db_Table{
	protected $_name = 'home';
	protected $_primary = 'id';
	public function listItem($arrParam = null, $options = null){										
		$db = $this->getAdapter();
		if($options['task'] == 'admin-list'){
			$select = $db->select()
						 ->from('home',array('id','title','description','header','footer','description_html','keywords_html'));
			$result  = $db->fetchAll($select);
		}
		return $result;
	}
	
	public function saveItem($arrParam = null, $options = null){
		if($options['task'] == 'admin-add'){
			$row =  $this->fetchNew();
		}
		$row->title 				= $arrParam['title'];
		$row->description_html 		= $arrParam['description_html'];
		$row->keywords_html 		= $arrParam['keywords_html'];
		$row->header 				= $arrParam['header'];
		$row->footer 				= $arrParam['footer'];
		$row->description 			= $arrParam['description'];
		$row->save();		
	}	
	
	public function sortItem($arrParam = null, $options = null){
		$items = $arrParam[$options['column']];
		if(count($items)>0){
			foreach ($items as $key => $val) {
				$where = 'id = ' . $key;				
				$data = array($options['column']=>$val);
				$this->update($data,$where);
			}
		}
	}
}